home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / SHKNAM.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  14KB  |  419 lines

  1. /*    SCCS Id: @(#)shknam.c    3.0    88/04/13
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /* shknam.c -- initialize a shop */
  6.  
  7. #include "hack.h"
  8. #include "eshk.h"
  9.  
  10. #ifdef OVLB
  11.  
  12. static void FDECL(mkshobj_at, (const struct shclass *,int,int));
  13. static void FDECL(findname, (char *,const char **));
  14. static int  FDECL(shkinit, (const struct shclass *,struct mkroom *));
  15.  
  16. static const char *shkliquors[] = {
  17.     /* Ukraine */
  18.     "Njezjin", "Tsjernigof", "Gomel", "Ossipewsk", "Gorlowka",
  19.     /* N. Russia */
  20.     "Konosja", "Weliki Oestjoeg", "Syktywkar", "Sablja",
  21.     "Narodnaja", "Kyzyl",
  22.     /* Silezie */
  23.     "Walbrzych", "Swidnica", "Klodzko", "Raciborz", "Gliwice",
  24.     "Brzeg", "Krnov", "Hradec Kralove",
  25.     /* Schweiz */
  26.     "Leuk", "Brig", "Brienz", "Thun", "Sarnen", "Burglen", "Elm",
  27.     "Flims", "Vals", "Schuls", "Zum Loch",
  28.     ""
  29. };
  30.  
  31. static const char *shkbooks[] = {
  32.     /* Eire */
  33.     "Skibbereen", "Kanturk", "Rath Luirc", "Ennistymon", "Lahinch",
  34.     "Kinnegad", "Lugnaquillia", "Enniscorthy", "Gweebarra",
  35.     "Kittamagh", "Nenagh", "Sneem", "Ballingeary", "Kilgarvan",
  36.     "Cahersiveen", "Glenbeigh", "Kilmihil", "Kiltamagh",
  37.     "Droichead Atha", "Inniscrone", "Clonegal", "Lisnaskea",
  38.     "Culdaff", "Dunfanaghy", "Inishbofin", "Kesh",
  39.     ""
  40. };
  41.  
  42. static const char *shkarmors[] = {
  43.     /* Turquie */
  44.     "Demirci", "Kalecik", "Boyabai", "Yildizeli", "Gaziantep",
  45.     "Siirt", "Akhalataki", "Tirebolu", "Aksaray", "Ermenak",
  46.     "Iskenderun", "Kadirli", "Siverek", "Pervari", "Malasgirt",
  47.     "Bayburt", "Ayancik", "Zonguldak", "Balya", "Tefenni",
  48.     "Artvin", "Kars", "Makharadze", "Malazgirt", "Midyat",
  49.     "Birecik", "Kirikkale", "Alaca", "Polatli", "Nallihan",
  50.     ""
  51. };
  52.  
  53. static const char *shkwands[] = {
  54.     /* Wales */
  55.     "Yr Wyddgrug", "Trallwng", "Mallwyd", "Pontarfynach",
  56.     "Rhaeader", "Llandrindod", "Llanfair-ym-muallt",
  57.     "Y-Fenni", "Measteg", "Rhydaman", "Beddgelert",
  58.     "Curig", "Llanrwst", "Llanerchymedd", "Caergybi",
  59.     /* Scotland */
  60.     "Nairn", "Turriff", "Inverurie", "Braemar", "Lochnagar",
  61.     "Kerloch", "Beinn a Ghlo", "Drumnadrochit", "Morven",
  62.     "Uist", "Storr", "Sgurr na Ciche", "Cannich", "Gairloch",
  63.     "Kyleakin", "Dunvegan",
  64.     ""
  65. };
  66.  
  67. static const char *shkrings[] = {
  68.     /* Hollandse familienamen */
  69.     "Feyfer", "Flugi", "Gheel", "Havic", "Haynin", "Hoboken",
  70.     "Imbyze", "Juyn", "Kinsky", "Massis", "Matray", "Moy",
  71.     "Olycan", "Sadelin", "Svaving", "Tapper", "Terwen", "Wirix",
  72.     "Ypey",
  73.     /* Skandinaviske navne */
  74.     "Rastegaisa", "Varjag Njarga", "Kautekeino", "Abisko",
  75.     "Enontekis", "Rovaniemi", "Avasaksa", "Haparanda",
  76.     "Lulea", "Gellivare", "Oeloe", "Kajaani", "Fauske",
  77.     ""
  78. };
  79.  
  80. static const char *shkfoods[] = {
  81.     /* Indonesia */
  82.     "Djasinga", "Tjibarusa", "Tjiwidej", "Pengalengan",
  83.     "Bandjar", "Parbalingga", "Bojolali", "Sarangan",
  84.     "Ngebel", "Djombang", "Ardjawinangun", "Berbek",
  85.     "Papar", "Baliga", "Tjisolok", "Siboga", "Banjoewangi",
  86.     "Trenggalek", "Karangkobar", "Njalindoeng", "Pasawahan",
  87.     "Pameunpeuk", "Patjitan", "Kediri", "Pemboeang", "Tringanoe",
  88.     "Makin", "Tipor", "Semai", "Berhala", "Tegal", "Samoe",
  89.     ""
  90. };
  91.  
  92. static const char *shkweapons[] = {
  93.     /* Perigord */
  94.     "Voulgezac", "Rouffiac", "Lerignac", "Touverac", "Guizengeard",
  95.     "Melac", "Neuvicq", "Vanzac", "Picq", "Urignac", "Corignac",
  96.     "Fleac", "Lonzac", "Vergt", "Queyssac", "Liorac", "Echourgnac",
  97.     "Cazelon", "Eypau", "Carignan", "Monbazillac", "Jonzac",
  98.     "Pons", "Jumilhac", "Fenouilledes", "Laguiolet", "Saujon",
  99.     "Eymoutiers", "Eygurande", "Eauze", "Labouheyre",
  100.     ""
  101. };
  102.  
  103. static const char *shktools[] = {
  104.     /* Spmi */
  105.     "Ymla", "Eed-morra", "Cubask", "Nieb", "Bnowr Falr", "Telloc Cyaj",
  106.     "Sperc", "Noskcirdneh", "Yawolloh", "Hyeghu", "Niskal", "Trahnil",
  107.     "Htargcm", "Enrobwem", "Kachzi Rellim", "Regien", "Donmyar",
  108.     "Yelpur", "Nosnehpets", "Stewe", "Renrut", "Zlaw", "Nosalnef",
  109.     "Rewuorb", "Rellenk", "Yad", "Cire Htims", "Y-crad", "Nenilukah", 
  110. #ifdef OVERLAY
  111.     "Erreip", "Nehpets", "Mron", "Snivek",
  112. #endif
  113. #ifdef MAC
  114.     "Nhoj-lee", "Evad\'kh", "Ettaw-noj", "Tsew-mot", "Ydna-s",
  115. #endif
  116. #ifdef AMIGA
  117.     "Falo", "Nosid-da\'r", "Ekim-p", "Rebrol-nek", "Noslo", "Yl-rednow",
  118.     "Mured-oog",
  119. #endif
  120. #ifdef VMS
  121.     "Lez-tneg", "Ytnu-haled", "Niknar",
  122. #endif
  123.     ""
  124. };
  125.  
  126. static const char *shkgeneral[] = {
  127.     /* Suriname */
  128.     "Hebiwerie", "Possogroenoe", "Asidonhopo", "Manlobbi",
  129.     "Adjama", "Pakka Pakka", "Kabalebo", "Wonotobo",
  130.     "Akalapi", "Sipaliwini",
  131.     /* Greenland */
  132.     "Annootok", "Upernavik", "Angmagssalik",
  133.     /* N. Canada */
  134.     "Aklavik", "Inuvik", "Tuktoyaktuk",
  135.     "Chicoutimi", "Ouiatchouane", "Chibougamau",
  136.     "Matagami", "Kipawa", "Kinojevis",
  137.     "Abitibi", "Maganasipi",
  138.     /* Iceland */
  139.     "Akureyri", "Kopasker", "Budereyri", "Akranes", "Bordeyri",
  140.     "Holmavik",
  141.     ""
  142. };
  143.  
  144. /*
  145.  * To add new shop types, all that is necessary is to edit the shtypes[] array.
  146.  * See mkroom.h for the structure definition. Typically, you'll have to lower
  147.  * some or all of the probability fields in old entries to free up some
  148.  * percentage for the new type.
  149.  *
  150.  * The placement type field is not yet used but will be in the near future.
  151.  *
  152.  * The iprobs array in each entry defines the probabilities for various kinds
  153.  * of artifacts to be present in the given shop type. You can associate with
  154.  * each percentage either a generic artifact type (represented by one of the
  155.  * *_SYM macros) or a specific artifact (represented by an onames.h define).
  156.  * In the latter case, prepend it with a unary minus so the code can know
  157.  * (by testing the sign) whether to use mkobj() or mksobj().
  158.  */
  159.  
  160. const struct shclass shtypes[] = {
  161.     {"general store", RANDOM_SYM,
  162. #ifdef SPELLS
  163.         44,
  164. #else
  165.         47,
  166. #endif
  167.         D_SHOP, {{100, RANDOM_SYM}, {0, 0}, {0, 0}}, (char **)shkgeneral},
  168.     {"used armor dealership", ARMOR_SYM, 14,
  169.         D_SHOP, {{90, ARMOR_SYM}, {10, WEAPON_SYM}, {0, 0}}, (char **)shkarmors},
  170.     {"second hand bookstore", SCROLL_SYM, 10, D_SHOP,
  171. #ifdef SPELLS
  172.         {{90, SCROLL_SYM}, {10, SPBOOK_SYM}, {0, 0}},
  173. #else
  174.         {{100, SCROLL_SYM}, {0, 0}, {0, 0}},
  175. #endif
  176.         (char **)shkbooks},
  177.     {"liquor emporium", POTION_SYM, 10, D_SHOP,
  178.         {{100, POTION_SYM}, {0, 0}, {0, 0}}, (char **)shkliquors},
  179.     {"antique weapons outlet", WEAPON_SYM, 5, D_SHOP,
  180.         {{90, WEAPON_SYM}, {10, ARMOR_SYM}, {0, 0}}, (char **)shkweapons},
  181.     {"delicatessen", FOOD_SYM, 5, D_SHOP,
  182.         {{95, FOOD_SYM}, {5, POTION_SYM}, {0, 0}}, (char **)shkfoods},
  183.     {"jewelers", RING_SYM, 3, D_SHOP,
  184.         {{85, RING_SYM}, {10, GEM_SYM}, {5, AMULET_SYM}, {0, 0}}, (char **)shkrings},
  185.     {"quality apparel and accessories", WAND_SYM, 3, D_SHOP,
  186.         {{90, WAND_SYM}, {5, -LEATHER_GLOVES}, {5, -ELVEN_CLOAK}, {0, 0}},
  187.          (char **)shkwands},
  188.     {"hardware store", TOOL_SYM, 3, D_SHOP,
  189.         {{100, TOOL_SYM}, {0, 0}, {0, 0}}, (char **)shktools},
  190.     /* Actually shktools is ignored; the code specifically chooses a
  191.      * random implementor name (the only shop type with random shopkeepers)
  192.      */
  193. #ifdef SPELLS
  194.     {"rare books", SPBOOK_SYM, 3, D_SHOP,
  195.         {{90, SPBOOK_SYM}, {10, SCROLL_SYM}, {0, 0}}, (char **)shkbooks},
  196. #endif
  197.     {NULL, 0, 0, 0, {{0, 0}, {0, 0}, {0, 0}}, (char **)0}
  198. };
  199.  
  200. static void
  201. mkshobj_at(shp, sx, sy)
  202. /* make an object of the appropriate type for a shop square */
  203. const struct shclass *shp;
  204. int sx, sy;
  205. {
  206.     register struct monst *mtmp;
  207.     int atype;
  208.     struct permonst *ptr;
  209.  
  210.     if (rn2(100) < dlevel && !MON_AT(sx, sy) && (ptr = mkclass(S_MIMIC)) &&
  211.                 (mtmp=makemon(ptr,sx,sy))) {
  212.         mtmp->mimic = 1;
  213.         /* note: makemon will set the mimic symbol to a shop item */
  214.         if (rn2(10) >= dlevel) {
  215.             mtmp->m_ap_type = M_AP_OBJECT;
  216.             mtmp->mappearance = STRANGE_OBJECT;
  217.         }
  218.     } else if ((atype = get_shop_item(shp - shtypes)) < 0)
  219.         (void) mksobj_at(-atype, sx, sy);
  220.     else (void) mkobj_at(atype, sx, sy, TRUE);
  221. }
  222.  
  223. static void
  224. findname(nampt, nlp)
  225. /* extract a shopkeeper name for the given shop type */
  226.     char *nampt;
  227.     const char *nlp[];
  228. {
  229.     register int i;
  230.  
  231.     for(i = 0; i < dlevel; i++)
  232.     if (strlen(nlp[i]) == 0) {
  233.         /* Not enough names, try general name */
  234.         if (nlp != shkgeneral)
  235.         findname(nampt, shkgeneral);
  236.         else
  237.         Strcpy(nampt, "Dirk");
  238.         return;
  239.     }
  240.     (void) strncpy(nampt, nlp[i-1], PL_NSIZ);
  241.     nampt[PL_NSIZ-1] = 0;
  242. }
  243.  
  244. static int
  245. shkinit(shp, sroom)    /* create a new shopkeeper in the given room */
  246. const struct shclass    *shp;
  247. struct mkroom    *sroom;
  248. {
  249.     register int sh, sx, sy;
  250.     struct monst *shk;
  251.  
  252.     /* place the shopkeeper in the given room */
  253.     sh = sroom->fdoor;
  254.     sx = doors[sh].x;
  255.     sy = doors[sh].y;
  256.  
  257.     /* check that the shopkeeper placement is sane */
  258.     if(sx == sroom->lx-1) sx++; else
  259.         if(sx == sroom->hx+1) sx--; else
  260.         if(sy == sroom->ly-1) sy++; else
  261.             if(sy == sroom->hy+1) sy--; else {
  262. #ifdef DEBUG
  263. # ifdef WIZARD
  264.             /* Said to happen sometimes, but I have never seen it. */
  265.             /* Supposedly fixed by fdoor change in mklev.c */
  266.             if(wizard) {
  267.                 register int j = sroom->doorct;
  268.  
  269.                 pline("Where is shopdoor?");
  270.                 pline("Room at (%d,%d),(%d,%d).",
  271.                   sroom->lx, sroom->ly, sroom->hx, sroom->hy);
  272.                 pline("doormax=%d doorct=%d fdoor=%d",
  273.                 doorindex, sroom->doorct, sh);
  274.                 while(j--) {
  275.                 pline("door [%d,%d]", doors[sh].x, doors[sh].y);
  276.                 sh++;
  277.                 }
  278.                 more();
  279.             }
  280. # endif
  281. #endif
  282.             return(-1);
  283.             }
  284.  
  285.     if(MON_AT(sx, sy)) rloc(m_at(sx, sy)); /* insurance */
  286.  
  287.     /* now initialize the shopkeeper monster structure */
  288.     if(!(shk = makemon(&mons[PM_SHOPKEEPER], sx, sy))) return(-1);
  289.     shk->isshk = shk->mpeaceful = 1;
  290.     shk->msleep = 0;
  291.     shk->mtrapseen = ~0;    /* we know all the traps already */
  292.     ESHK(shk)->shoproom = sroom - rooms;
  293.     ESHK(shk)->shoplevel = dlevel;
  294.     ESHK(shk)->shd = doors[sh];
  295.     ESHK(shk)->shk.x = sx;
  296.     ESHK(shk)->shk.y = sy;
  297.     ESHK(shk)->robbed = 0L;
  298.     ESHK(shk)->credit = 0L;
  299.     ESHK(shk)->debit = 0L;
  300.     ESHK(shk)->visitct = 0;
  301.     ESHK(shk)->following = 0;
  302.     ESHK(shk)->billct = 0;
  303.     shk->mgold = 1000L + 30L*(long)rnd(100);    /* initial capital */
  304.     if (shp->shknms == (char **)shktools) {
  305.         static int NEARDATA who;
  306.         who = rn2(sizeof(shktools)/sizeof(char *) - 1);
  307.         if (who==21) ESHK(shk)->ismale = FALSE;
  308.         else ESHK(shk)->ismale = TRUE;
  309.         (void) strncpy(ESHK(shk)->shknam, shp->shknms[who], PL_NSIZ);
  310.         ESHK(shk)->shknam[PL_NSIZ-1] = 0;
  311.     } else {
  312.         ESHK(shk)->ismale = dlevel%2;
  313.         findname(ESHK(shk)->shknam, (const char **)shp->shknms);
  314.     }
  315.  
  316.     return(sh);
  317. }
  318.  
  319. void
  320. stock_room(shp, sroom)
  321. /* stock a newly-created room with artifacts */
  322. const struct shclass    *shp;
  323. register struct mkroom *sroom;
  324. {
  325.     /*
  326.      * Someday soon we'll dispatch on the dist field of shclass to do
  327.      * different placements in this routine. Currently it only supports
  328.      * shop-style placement (all squares except a row nearest the first
  329.      * door get artifacts).
  330.      */
  331.     register int sx, sy, sh;
  332.     char buf[BUFSZ];
  333.  
  334.     /* first, try to place a shopkeeper in the room */
  335.     if ((sh = shkinit(shp, sroom)) < 0)
  336.     return;
  337.  
  338.     /* make sure no doorways without doors, and no */
  339.     /* trapped doors, in shops.               */
  340.     sx = doors[sroom->fdoor].x;
  341.     sy = doors[sroom->fdoor].y;
  342.  
  343.     if(levl[sx][sy].doormask == D_NODOOR) {
  344.         levl[sx][sy].doormask = D_ISOPEN;
  345.         mnewsym(sx,sy);
  346.     }
  347.     if(levl[sx][sy].typ == SDOOR) {
  348.         levl[sx][sy].typ = DOOR;
  349.         mnewsym(sx,sy);
  350.     }
  351.     if(levl[sx][sy].doormask & D_TRAPPED) {    
  352.         levl[sx][sy].doormask &= ~D_TRAPPED;
  353.         levl[sx][sy].doormask = D_LOCKED;
  354.     }
  355.  
  356.     if(levl[sx][sy].doormask == D_LOCKED) {
  357.         register int m = sx, n = sy;
  358.  
  359.         if(IS_ROOM(levl[sx+1][sy].typ)) m--;
  360.         else if(IS_ROOM(levl[sx-1][sy].typ)) m++;
  361.         if(IS_ROOM(levl[sx][sy+1].typ)) n--;
  362.         else if(IS_ROOM(levl[sx][sy-1].typ)) n++;
  363.         Sprintf(buf, "Closed for inventory"); 
  364.         make_engr_at(m, n, buf); 
  365.     }
  366.  
  367.     for(sx = sroom->lx; sx <= sroom->hx; sx++)
  368.     for(sy = sroom->ly; sy <= sroom->hy; sy++) {
  369.         if((sx == sroom->lx && doors[sh].x == sx-1) ||
  370.            (sx == sroom->hx && doors[sh].x == sx+1) ||
  371.            (sy == sroom->ly && doors[sh].y == sy-1) ||
  372.            (sy == sroom->hy && doors[sh].y == sy+1)) continue;
  373.         mkshobj_at(shp, sx, sy);
  374.     }
  375.  
  376.     /*
  377.      * Special monster placements (if any) should go here: that way,
  378.      * monsters will sit on top of artifacts and not the other way around.
  379.      */
  380. }
  381.  
  382. #endif /* OVLB */
  383. #ifdef OVL0
  384.  
  385. int
  386. saleable(nshop, obj)            /* does "shop" stock this item type */
  387. register int nshop;
  388. register struct    obj *obj;
  389. {
  390.     int i;
  391.  
  392.     if(shtypes[nshop].symb == RANDOM_SYM) return(1);
  393.     else {
  394.         for(i = 0; shtypes[nshop].iprobs[i].iprob; i++)
  395.         if(shtypes[nshop].iprobs[i].itype < 0) {
  396.            if(shtypes[nshop].iprobs[i].itype == - obj->otyp) return(1);
  397.         }
  398.         else if(shtypes[nshop].iprobs[i].itype == obj->olet) return(1);
  399.     }
  400.     return(0);
  401. }
  402.  
  403. /* positive value: letter; negative value: specific item type */
  404. int
  405. get_shop_item(type)
  406. int type;
  407. {
  408.     const struct shclass *shp = shtypes+type;
  409.     register int i,j;
  410.  
  411.     /* select an appropriate artifact type at random */
  412.     for(j = rnd(100), i = 0; j -= shp->iprobs[i].iprob; i++)
  413.         if (j < 0) break;
  414.  
  415.     return shp->iprobs[i].itype;
  416. }
  417.  
  418. #endif /* OVL0 */
  419.